<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
  <meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Reflection &mdash; The Logtalk Handbook v3.93.0-b01 documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=d75fae25" />
      <link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
      <link rel="stylesheet" type="text/css" href="../_static/css/custom.css?v=396eccfe" />

  
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script src="../_static/jquery.js?v=5d32c60e"></script>
        <script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
        <script src="../_static/documentation_options.js?v=c8100655"></script>
        <script src="../_static/doctools.js?v=9a2dae69"></script>
        <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/js/theme.js"></script>
    <!-- begin favicon -->
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
    <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
    <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
    <link rel="manifest" href="/site.webmanifest" />
    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5" />
    <meta name="msapplication-TileColor" content="#355b95" />
    <meta name="theme-color" content="#ffffff" />
    <!-- end favicon -->
    
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Writing and running applications" href="programming.html" />
    <link rel="prev" title="Error handling" href="errors.html" />
   
</head>

<body class="wy-body-for-nav"> 
  <div class="wy-grid-for-nav">
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >

          
          
          <a href="../index.html" class="icon icon-home">
            The Logtalk Handbook
              <img src="../_static/logtalk.gif" class="logo" alt="Logo"/>
          </a>
              <div class="version">
                3.93.0
              </div>
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
        </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
    
              <p class="caption" role="heading"><span class="caption-text">Contents</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">User Manual</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="declarative.html">Declarative object-oriented programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="features.html">Main features</a></li>
<li class="toctree-l2"><a class="reference internal" href="nomenclature.html">Nomenclature</a></li>
<li class="toctree-l2"><a class="reference internal" href="messages.html">Messages</a></li>
<li class="toctree-l2"><a class="reference internal" href="objects.html">Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="protocols.html">Protocols</a></li>
<li class="toctree-l2"><a class="reference internal" href="categories.html">Categories</a></li>
<li class="toctree-l2"><a class="reference internal" href="predicates.html">Predicates</a></li>
<li class="toctree-l2"><a class="reference internal" href="inheritance.html">Inheritance</a></li>
<li class="toctree-l2"><a class="reference internal" href="events.html">Event-driven programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="threads.html">Multi-threading programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="errors.html">Error handling</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Reflection</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#structural-reflection">Structural reflection</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#transparent-box-view">Transparent-box view</a></li>
<li class="toctree-l4"><a class="reference internal" href="#black-box-view">Black-box view</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#behavioral-reflection">Behavioral reflection</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="programming.html">Writing and running applications</a></li>
<li class="toctree-l2"><a class="reference internal" href="printing.html">Printing messages and asking questions</a></li>
<li class="toctree-l2"><a class="reference internal" href="expansion.html">Term and goal expansion</a></li>
<li class="toctree-l2"><a class="reference internal" href="documenting.html">Documenting</a></li>
<li class="toctree-l2"><a class="reference internal" href="debugging.html">Debugging</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance.html">Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="installing.html">Installing Logtalk</a></li>
<li class="toctree-l2"><a class="reference internal" href="migration.html">Prolog integration and migration</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../refman/index.html">Reference Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devtools/index.html">Developer Tools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../libraries/index.html">Libraries</a></li>
<li class="toctree-l1"><a class="reference internal" href="../ports/index.html">Ports</a></li>
<li class="toctree-l1"><a class="reference internal" href="../contributions/index.html">Contributions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
<li class="toctree-l1"><a class="reference internal" href="../bibliography.html">Bibliography</a></li>
<li class="toctree-l1"><a class="reference internal" href="../genindex.html">Index</a></li>
</ul>

    <p class="caption"><span class="caption-text">External Contents</span></p>
    <ul>
    <li class="toctree-l1"><a class="reference internal" href="../../apis/index.html">APIs</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://logtalk.org">Logtalk website</a></li>
    <li class="toctree-l1"><a class="reference internal" href="https://github.com/LogtalkDotOrg/logtalk3">GitHub repo</a></li>
    </ul>
  
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">The Logtalk Handbook</a>
      </nav>

      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="Page navigation">
  <ul class="wy-breadcrumbs">
      <li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
          <li class="breadcrumb-item"><a href="index.html">User Manual</a></li>
      <li class="breadcrumb-item active">Reflection</li>
      <li class="wy-breadcrumbs-aside">
              <a href="https://github.com/LogtalkDotOrg/logtalk3/blob/master/docs/handbook/sources/userman/reflection.rst" class="fa fa-github"> Edit on GitHub</a>
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
             
  <section id="reflection">
<span id="reflection-reflection"></span><span id="index-0"></span><h1>Reflection<a class="headerlink" href="#reflection" title="Link to this heading"></a></h1>
<p>Logtalk provides support for both <em>structural</em> and <em>behavioral</em> reflection.
Structural reflection supports computations over an application structure.
Behavioral reflection supports computations over what an application does while
running. The structural and behavioral reflection APIs are used by all the
<a class="reference internal" href="../devtools/index.html"><span class="doc">developer tools</span></a>, which are regular applications.</p>
<section id="structural-reflection">
<span id="reflection-structural"></span><span id="index-1"></span><h2>Structural reflection<a class="headerlink" href="#structural-reflection" title="Link to this heading"></a></h2>
<p>Structural reflection allows querying the properties of objects, categories,
protocols, and predicates. This API provides two views on the structure of
an application: a <em>transparent-box view</em> and a <em>black-box view</em>, described
next.</p>
<section id="transparent-box-view">
<span id="index-2"></span><h3>Transparent-box view<a class="headerlink" href="#transparent-box-view" title="Link to this heading"></a></h3>
<p>The transparent-box view provides a structural view of the contents and
properties of entities, predicates, and source files akin to accessing
the corresponding source code. I.e. this is the view we use when asking
questions such as: <em>What predicates are declared in this protocol?</em>
<em>Which predicates are called by this predicate?</em> <em>Where are clauses for
this multifile predicate defined?</em></p>
<p>For entities, built-in predicates are provided for
<a class="reference internal" href="../refman/predicates/enumerating_entity_predicates.html#enumerating-entity-predicates"><span class="std std-ref">enumerating entities</span></a>,
<a class="reference internal" href="../refman/predicates/enumerating_entity_property_predicates.html#enumerating-entity-property-predicates"><span class="std std-ref">enumerating entity properties</span></a>
(including entity declared, defined, called, and updated predicates; i.e.
full predicate cross-referencing data), and
<a class="reference internal" href="../refman/predicates/entity_relation_predicates.html#entity-relation-predicates"><span class="std std-ref">enumerating entity relations</span></a> (for full
entity cross-referencing data).
For a detailed description of the supported entity properties, see the sections
on <a class="reference internal" href="objects.html#objects-properties"><span class="std std-ref">object properties</span></a>,
<a class="reference internal" href="protocols.html#protocols-properties"><span class="std std-ref">protocol properties</span></a>, and
<a class="reference internal" href="categories.html#categories-properties"><span class="std std-ref">category properties</span></a>.
For examples of querying entity relations, see the sections
on <a class="reference internal" href="objects.html#objects-relationships"><span class="std std-ref">object relations</span></a>,
<a class="reference internal" href="protocols.html#protocols-relationships"><span class="std std-ref">protocol relations</span></a>, and
<a class="reference internal" href="categories.html#categories-relationships"><span class="std std-ref">category relations</span></a>.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Some entity and predicate properties are only available when the source
files are compiled with the <a class="reference internal" href="programming.html#flag-source-data"><span class="std std-ref">source_data</span></a> flag
turned on.</p>
</div>
<p>The <a class="reference external" href="../../apis/logtalk_0.html#logtalk-0" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">logtalk</span></a> built-in object provides predicates for
querying loaded source files and their properties.</p>
</section>
<section id="black-box-view">
<span id="index-3"></span><h3>Black-box view<a class="headerlink" href="#black-box-view" title="Link to this heading"></a></h3>
<p>The black-box view provides a view that takes into account entity encapsulation
and thus only allows querying about predicates and operators that are within
the scope of the entity calling the reflection methods. This is the view we use
when asking questions such as: <em>What messages can be sent to this object?</em></p>
<p>Built-in methods are provided for querying the <a class="reference internal" href="../refman/methods/current_predicate_1.html#methods-current-predicate-1"><span class="std std-ref">predicates that are
declared and can be called or used as messages</span></a>
and for querying the <a class="reference internal" href="../refman/methods/predicate_property_2.html#methods-predicate-property-2"><span class="std std-ref">predicate properties</span></a>.
It is also possible to enumerate <a class="reference internal" href="../refman/methods/current_op_3.html#methods-current-op-3"><span class="std std-ref">entity operators</span></a>.
See the sections on <a class="reference internal" href="predicates.html#predicates-finding"><span class="std std-ref">finding declared predicates</span></a> and
on <a class="reference internal" href="predicates.html#predicates-properties"><span class="std std-ref">predicate properties</span></a> for more details.</p>
</section>
</section>
<section id="behavioral-reflection">
<span id="reflection-behavioral"></span><span id="index-4"></span><h2>Behavioral reflection<a class="headerlink" href="#behavioral-reflection" title="Link to this heading"></a></h2>
<p>Behavioral reflection provides insight on what an application does when running.
Specifically, by observing and acting on the messages being exchanged between
objects. See the section on <a class="reference internal" href="events.html#events-events"><span class="std std-ref">event-driven programming</span></a>
for details. There is also a <a class="reference internal" href="../libraries/dependents.html"><span class="doc">dependents</span></a> library that
provides an implementation of Smalltalk dependents mechanism.</p>
<p>For use in debugging tools, there is also a small reflection API providing
<a class="reference internal" href="debugging.html#debugging-events"><span class="std std-ref">trace and debug event predicates</span></a> provided by the
<a class="reference external" href="../../apis/logtalk_0.html#logtalk-0" title="(in Logtalk APIs v3.93.0)"><span class="xref std std-ref">logtalk</span></a> built-in object.</p>
</section>
</section>


           </div>
          </div>
          <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
        <a href="errors.html" class="btn btn-neutral float-left" title="Error handling" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
        <a href="programming.html" class="btn btn-neutral float-right" title="Writing and running applications" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
    </div>

  <hr/>

  <div role="contentinfo">
    <p>&#169; Copyright 1998-2025, Paulo Moura.</p>
  </div>

  Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    provided by <a href="https://readthedocs.org">Read the Docs</a>.
   

</footer>
        </div>
      </div>
    </section>
  </div>
  <script>
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>